package com.ddz.model;

public class Poker{
    private static final long serialVersionUID = 1L;
    // 牌名
    private final String name;
    // 牌值
    private final String value;

    // 构造函数：只接受 value 参数，根据 value 推算出 name
    public Poker(String value) {
        this.value = value;
        this.name = generateName(value);
    }

    private String generateName(String pokerValue) {
        String[] split = pokerValue.split("-");
        String pokerSex;
        String pokerNum;
        switch (split[0]) {
            case "1":
                pokerSex = "黑桃";
                break;
            case "2":
                pokerSex = "红桃";
                break;
            case "3":
                pokerSex = "梅花";
                break;
            case "4":
                pokerSex = "方块";
                break;
            default:
                pokerSex = "王";
                return split[1].equals("1") ? "小" + pokerSex : "大" + pokerSex;
        }

        int num = Integer.parseInt(split[1]);
        switch (num) {
            case 1:
                pokerNum = "A";
                break;
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
                pokerNum = String.valueOf(num);
                break;
            case 11:
                pokerNum = "J";
                break;
            case 12:
                pokerNum = "Q";
                break;
            case 13:
                pokerNum = "K";
                break;
            default:
                pokerNum = "0";
        }
        return pokerSex + pokerNum;
    }

    public String getName() {
        return name;
    }

    public String getValue() {
        return value;
    }

    @Override
    public String toString() {
        return name;
    }
}